﻿using DevExpress.XtraEditors;
using DXApplicationTangche.UC.圣同润.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.圣同润
{
    public partial class Form商品一览 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private String category { get; set; }
        private List<GoodsFileDao> goodsFileDaos = new List<GoodsFileDao>();
        public Form商品一览(String category)
        {
            InitializeComponent();
            this.category = category;
            this.getGoodsData(category);
            this.getUnimilarProductData(category);
            this.getDarenProductData(category);
        }
        private void getDarenProductData(String category)
        {
            //  商品分类下的达人商品信息
            List<ViewChanmamaDarenProductInfoDao> viewChanmamaDarenProductInfoDaos = 
                圣同润Service.getChanmamaDarenProductInfoByCategory(category);
            this.gridControl商品达人分组.DataSource = viewChanmamaDarenProductInfoDaos;
            this.gridView商品达人分组.RefreshData();

        }
        private void getGoodsData(String className)
        {
            //  货品一览
            this.goodsFileDaos = 货品Service.getGoodsFileAll(className);
            this.gridControl货品一览.DataSource = this.goodsFileDaos;
            this.gridView货品一览.RefreshData();
        }
        private void getProductData(String originalProductId, String category)
        {
            //  相似竞品
            ProductIndexDTO productIndexDTO = 圣同润Service.getProductIndexByOriginalProductId(originalProductId, category);
            for (int i = 0; i < productIndexDTO.productIndexMetaElementDTOS.Count; i++)
            {
                int index = i + 1;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).Caption
                    = productIndexDTO.productIndexMetaElementDTOS[i].caption;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).Visible
                    = productIndexDTO.productIndexMetaElementDTOS[i].visible;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).FieldName
                    = productIndexDTO.productIndexMetaElementDTOS[i].fieldName;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).VisibleIndex = index + 3;
            }
            this.gridControl商品分类一览.DataSource = productIndexDTO.viewChanmamaProductClassInfoDaos;
            this.gridView商品分类一览.RefreshData();
        }
        private void getUnimilarProductData(String category)
        {
            //  相似度低获取商品分类一览
            ProductIndexDTO unimilarProductDTO = 圣同润Service.getUnimilarProductIndexAll(category);
            for (int i = 0; i < unimilarProductDTO.productIndexMetaElementDTOS.Count; i++)
            {
                int index = i + 1;
                this.gridView似度低商品一览.Columns.ColumnByName("gridColumnUN" + index).Caption
                    = unimilarProductDTO.productIndexMetaElementDTOS[i].caption;
                this.gridView似度低商品一览.Columns.ColumnByName("gridColumnUN" + index).Visible
                    = unimilarProductDTO.productIndexMetaElementDTOS[i].visible;
                this.gridView似度低商品一览.Columns.ColumnByName("gridColumnUN" + index).FieldName
                    = unimilarProductDTO.productIndexMetaElementDTOS[i].fieldName;
                this.gridView似度低商品一览.Columns.ColumnByName("gridColumnUN" + index).VisibleIndex = index + 3;
            }
            this.gridControl相似度低商品一览.DataSource = unimilarProductDTO.viewChanmamaProductClassInfoDaos;
            this.gridView似度低商品一览.RefreshData();
        }
        private void 查看竞品详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String productId = this.gridView商品分类一览.GetRowCellValue(this.gridView商品分类一览.FocusedRowHandle, "productId").ToString();
                new Form商品信息(productId).ShowDialog();
            }
            catch { }
        }

        private void barButtonItem新增在售商品_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new Form货品档案新增(this.category).ShowDialog();
            this.getGoodsData(this.category);
        }

        private void gridView货品一览_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                String goodsNo = this.gridView货品一览.GetRowCellValue(this.gridView货品一览.FocusedRowHandle, "goodsNo").ToString();
                this.getProductData(goodsNo, this.category);
            }
            catch { }
        }
    }
}